package edu.uow.devdocs

import org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass

class PersonController {
	
	static scaffold = true
	def currentUserService
	
    def save() {
        def personInstance = new Person(params)
        if (!personInstance.save(flush: true)) {
            render(view: "create", model: [personInstance: personInstance])
            return
        }
		new SecUser(username:personInstance?.username,'password':personInstance?.username,'enabled':true).save(flush:true)

		flash.message = message(code: 'default.created.message', args: [message(code: 'Person.label', default: 'Person'), personInstance.id])
        redirect(action: "edit", id: personInstance.id)
    }
	
	def savePreferredProjects() {
		println params
		session.filterProject = params.list('filterProject').collect{ Project.get(it)}
		session.filterProject = session.filterProject.unique()
		println session.filterProject
		render "success"
	}

	
	def getProjectFilter() {
		def projectList = currentUserService.currentUser.projects
		render(template:'/shared/projectFilter', model:[projectList:projectList])
	}
	

	
}
